package com.aqsare;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class pattern implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2271786937374904229L;
	private static SimpleConfig config = new SimpleConfig(SimpleConfig.RESOURCE_NAME);
	private int ampli;
	private ArrayList<punct> puncte;
	
	
	public pattern(int ampli){
		
		this.setAmpli(ampli);
		puncte=new ArrayList<punct>();
		
	}
	public pattern(int ampli, punct punctu){
		
		this.setAmpli(ampli);
		puncte=new ArrayList<punct>();
		puncte.add(punctu);
		
	}

	public int getAmpli() {
		return ampli;
		
	}

	public void setAmpli(int ampli) {
		this.ampli = ampli;
	}
	
	public punct getPunct(int care) {
		return puncte.get(care);
	}

	public void addPunct(punct punctu) {
		//System.out.println("new punct x="+punctu.getDtimp()+", y="+punctu.getDpip());
		puncte.add(punctu);
	}
	
	public indicator addPunctMaxSize(punct punctu, int maxlen, indicator last_max) {
	if ((punctu.getDpip()==0)||(puncte.get(puncte.size()-1).getDpip()==punctu.getDpip()))  return last_max;

		puncte.add(punctu);
	
		if (puncte.size()>maxlen){
			int swift=puncte.get(0).getDpip();
			int swifyt=puncte.get(0).getDtimp();
			
			for (int i = 1; i < puncte.size(); i++) {
				puncte.get(i).setDpip(puncte.get(i).getDpip()-swift);
				puncte.get(i).setDtimp(puncte.get(i).getDtimp()-swifyt);
			}
		
			puncte.remove(0);
			last_max.setVal(last_max.getVal()-swift/100000);
			last_max.setMax(last_max.getMax()-swifyt);
			return last_max;
		}
		else return last_max;
	}
	public void removePunct(int punctu) {
		puncte.remove(punctu);
	} 
	
	
	public boolean eqTrend(pattern comppatt){
	return (((this.getAmpli() > 0) && (comppatt.getAmpli() < 0))||((this.getAmpli() < 0) && (comppatt.getAmpli() > 0)));
		
	}

	public boolean eq(pattern comppatt) {
		int count_0 = 0;
		if (this.sizePatt() > 1)
			for (int j = 0; j < this.sizePatt(); j++)
				for (int w = 0; w < comppatt.sizePatt(); w++)
					if (this.getPunct(j).getDpip() == comppatt.getPunct(w).getDpip())
						count_0++;
//int cont =(int)(this.sizePatt()*config.getComparePoints()/100);

		if (count_0 > (int)(this.sizePatt()*config.getComparePoints()/100))
			return true;
		else
			return false;
	}
	
	public boolean eqShift(pattern comppatt) {
		int count_0 = 0;
		if (this.sizePatt() > 1)
			for (int j = 0; j < this.sizePatt(); j++)
				for (int w = 0; w < comppatt.sizePatt(); w++)
					if ((this.getPunct(j).getDpip() > comppatt.getPunct(w).getDpip()-config.getShiftCompare())&& (this.getPunct(j).getDpip() < comppatt.getPunct(w).getDpip()+config.getShiftCompare()))
						count_0++;
//int cont =(int)(this.sizePatt()*config.getComparePoints()/100);

		if (count_0 > (int)(this.sizePatt()*config.getComparePoints()/100))
			return true;
		else
			return false;
	}
	
	
	public int sizePatt() {
		return puncte.size();
	}
	

}
